﻿
namespace Mulala.Cavan.Application.MainBoundedContext.NannyModule
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Mulala.Cavan.Domain.MainBoundedContext.NannyModule;
    using Mulala.Cavan.Domain.MainBoundedContext.SearchModule;
    using Mulala.Cavan.Domain.Seedwork;
    using Spring.Context;
    using Spring.Context.Support;
    using Mulala.Cavan.Application.MainBoundedContext.ProprietorModule;
    using Mulala.Cavan.Domain.MainBoundedContext.ProprietorModule;


    public class NannyCommentAppService : BaseAppService<NannyComment, NannyCommentSearch, INannyCommentRepository>, INannyCommentAppService
    {
        private IApplicationContext SpringContext = null;
        private IProprietorAppService ProprietorAppService { get; set; }
        private INannyAppService NannyAppService { get; set; }

        public override BoolGenericResult<NannyComment> Add(NannyComment newNannyComment)
        {
            this.SpringContext = ContextRegistry.GetContext();
            this.ProprietorAppService = this.SpringContext.GetObject("ProprietorAppService") as IProprietorAppService;
            this.NannyAppService = this.SpringContext.GetObject("NannyAppService") as INannyAppService;

            BoolGenericResult<NannyComment> result = new BoolGenericResult<NannyComment>();
            Proprietor proprietor = this.ProprietorAppService.GetById(newNannyComment.Proprietor.ID);
            Nanny nanny = this.NannyAppService.GetById(newNannyComment.Nanny.ID);
            result = proprietor.CommentNanny(nanny, newNannyComment.Content, newNannyComment.InfoAuthentic, newNannyComment.WorkProficient, newNannyComment.PersonalIntegrity,
                newNannyComment.PersonalCharm);

            if (result.IsSuccess)
            {
                this.Repository.Save(result.Object);
            }

            return result;
        }
    }
}
